package com.financing.wap.weixin.test;

import java.io.StringReader;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import com.financing.wap.weixin.util.XMLParse;


public class test {
public static void main(String[] args) throws Exception {
	
	//token:QDG6eK 
	//encodingAesKey:jWmYm7qr5nMoAUwZRjGtBxmz3KA1tkAj3ykkR6q2B2C
	 WXBizMsgCrypt wxcpt = new WXBizMsgCrypt("QDG6eK",	
				"jWmYm7qr5nMoAUwZRjGtBxmz3KA1tkAj3ykkR6q2B2C");
	 
	 //参数
		String loginname = "15000774677";	
		String password = "lisu8906363sfa";
		
	//生成XML
		String pxml = XMLParse.generateSfaP(loginname, password);
	
	//加密后的XML
		String jiamiPxml  = wxcpt.encryptMsg(pxml);
		
		System.out.println("加密："+jiamiPxml);
		
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		DocumentBuilder db = dbf.newDocumentBuilder();
		StringReader sr = new StringReader(jiamiPxml);
		InputSource is = new InputSource(sr);
		Document document = db.parse(is);

		Element root = document.getDocumentElement();
		NodeList nodelist1 = root.getElementsByTagName("Encrypt");
		NodeList nodelist2 = root.getElementsByTagName("MsgSignature");

//		String encrypt = nodelist1.item(0).getTextContent();
//		String msgSignature = nodelist2.item(0).getTextContent();
//		
//		String result2 = wxcpt.decryptMsg(msgSignature,  encrypt);
//		System.out.println("解密后明文: " + result2);
		
		
}
}
